// Copyright (c) eBPF for Windows contributors
// SPDX-License-Identifier: MIT

/**
 * @brief Defines prototype structures for program information for general helper functions (aka global functions)
 * implemented by the eBPF core Execution Context.
 */

#include "ebpf_program_types.h"
#include "ebpf_shared_framework.h"
#include "ebpf_structs.h"

ebpf_helper_function_prototype_t ebpf_core_helper_function_prototype_array[] = {
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_lookup_elem,
     "bpf_map_lookup_elem",
     EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_update_elem,
     "bpf_map_update_elem",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP,
      EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY,
      EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE,
      EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_delete_elem,
     "bpf_map_delete_elem",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_lookup_and_delete_elem,
     "bpf_map_lookup_and_delete_elem",
     EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_tail_call,
     "bpf_tail_call",
     EBPF_RETURN_TYPE_INTEGER_OR_NO_RETURN_IF_SUCCEED,
     {EBPF_ARGUMENT_TYPE_PTR_TO_CTX, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_OF_PROGRAMS, EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_get_prandom_u32,
     "bpf_get_prandom_u32",
     EBPF_RETURN_TYPE_INTEGER,
     {0}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_ktime_get_boot_ns,
     "bpf_ktime_get_boot_ns",
     EBPF_RETURN_TYPE_INTEGER,
     {0}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_get_smp_processor_id,
     "bpf_get_smp_processor_id",
     EBPF_RETURN_TYPE_INTEGER,
     {0}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER, BPF_FUNC_ktime_get_ns, "bpf_ktime_get_ns", EBPF_RETURN_TYPE_INTEGER, {0}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_csum_diff,
     "bpf_csum_diff",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM_OR_NULL,
      EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
      EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM_OR_NULL,
      EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
      EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_ringbuf_output,
     "bpf_ringbuf_output",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP,
      EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
      EBPF_ARGUMENT_TYPE_CONST_SIZE,
      EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_trace_printk2,
     "bpf_trace_printk2",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM, EBPF_ARGUMENT_TYPE_CONST_SIZE}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_trace_printk3,
     "bpf_trace_printk3",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM, EBPF_ARGUMENT_TYPE_CONST_SIZE, EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_trace_printk4,
     "bpf_trace_printk4",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
      EBPF_ARGUMENT_TYPE_CONST_SIZE,
      EBPF_ARGUMENT_TYPE_ANYTHING,
      EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_trace_printk5,
     "bpf_trace_printk5",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
      EBPF_ARGUMENT_TYPE_CONST_SIZE,
      EBPF_ARGUMENT_TYPE_ANYTHING,
      EBPF_ARGUMENT_TYPE_ANYTHING,
      EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_push_elem,
     "bpf_map_push_elem",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE, EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_pop_elem,
     "bpf_map_pop_elem",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_map_peek_elem,
     "bpf_map_peek_elem",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_get_current_pid_tgid,
     "bpf_get_current_pid_tgid",
     EBPF_RETURN_TYPE_INTEGER,
     {0}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_get_current_logon_id,
     "bpf_get_current_logon_id",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_CTX}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_is_current_admin,
     "bpf_is_current_admin",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_CTX}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_memcpy,
     "bpf_memcpy",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_WRITABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_memcmp,
     "bpf_memcmp",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_memset,
     "bpf_memset",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_WRITABLE_MEM, EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO, EBPF_ARGUMENT_TYPE_ANYTHING}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_memmove,
     "bpf_memmove",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_WRITABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_get_socket_cookie,
     "bpf_get_socket_cookie",
     EBPF_RETURN_TYPE_INTEGER,
     {EBPF_ARGUMENT_TYPE_PTR_TO_CTX}},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_strncpy_s,
     "bpf_strncpy_s",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_WRITABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_strncat_s,
     "bpf_strncat_s",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_WRITABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
    {EBPF_HELPER_FUNCTION_PROTOTYPE_HEADER,
     BPF_FUNC_strnlen_s,
     "bpf_strnlen_s",
     EBPF_RETURN_TYPE_INTEGER,
     {
         EBPF_ARGUMENT_TYPE_PTR_TO_READABLE_MEM,
         EBPF_ARGUMENT_TYPE_CONST_SIZE_OR_ZERO,
     }},
};

#ifdef __cplusplus
extern "C"
{
#endif

    ebpf_helper_function_prototype_t* ebpf_core_helper_function_prototype =
        &ebpf_core_helper_function_prototype_array[0];
    uint32_t ebpf_core_helper_functions_count = EBPF_COUNT_OF(ebpf_core_helper_function_prototype_array);

#ifdef __cplusplus
}
#endif
